/**
  **************************************************************************
  * @file     at32f425_board.h
  * @brief    header file for at-start board. set of firmware functions to
  *           manage leds and push-button. initialize delay function.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#ifndef __FLDRV_BOARD_H
#define __FLDRV_BOARD_H

#ifdef __cplusplus
extern "C" {
#endif

#include "stdio.h"
#include "at32f425.h"

/** @addtogroup AT32F425_board
  * @{
  */

/** @addtogroup BOARD
  * @{
  */

/** @defgroup BOARD_pins_definition
  * @{
  */

/**
  * this header include define support list:
  * 1. at-start-f425 v1.x boards
  * if define AT_START_F425_V1, the header file support at-start-f425 v1.x board
  */

#if !defined (AT_START_F425_V1)
#error "please select first the board at-start device used in your application (in at32f425_board.h file)"
#endif

/******************** define led ********************/
typedef enum
{
  EN_LED       = 0,
  EN_DIS,
	EN_ION,
  EN_PM25,   
	EN_FAN,
	EN_TH,
	EN_RS485,
	EN_4G,
	EN_NUM,
} en_type;


#if defined (AT_START_F425_V1)
#define EN_LED_PIN                       GPIO_PINS_8
#define EN_LED_GPIO                      GPIOA
#define EN_LED_GPIO_CRM_CLK              CRM_GPIOA_PERIPH_CLOCK

#define EN_DIS_PIN                       GPIO_PINS_5
#define EN_DIS_GPIO                      GPIOA
#define EN_DIS_GPIO_CRM_CLK              CRM_GPIOA_PERIPH_CLOCK

#define EN_ION_PIN                       GPIO_PINS_13
#define EN_ION_GPIO                      GPIOC
#define EN_ION_GPIO_CRM_CLK              CRM_GPIOC_PERIPH_CLOCK

#define EN_PM25_PIN                      GPIO_PINS_14
#define EN_PM25_GPIO                     GPIOC
#define EN_PM25_GPIO_CRM_CLK             CRM_GPIOC_PERIPH_CLOCK

#define EN_FAN_PIN                       GPIO_PINS_7
#define EN_FAN_GPIO                      GPIOB
#define EN_FAN_GPIO_CRM_CLK              CRM_GPIOB_PERIPH_CLOCK

#define EN_TH_PIN                        GPIO_PINS_12
#define EN_TH_GPIO                       GPIOB
#define EN_TH_GPIO_CRM_CLK               CRM_GPIOB_PERIPH_CLOCK

#define EN_RS485_PIN                     GPIO_PINS_4
#define EN_RS485_GPIO                    GPIOA
#define EN_RS485_GPIO_CRM_CLK            CRM_GPIOA_PERIPH_CLOCK

#define EN_4G_PIN                     	 GPIO_PINS_7
#define EN_4G_GPIO                    	 GPIOF
#define EN_4G_GPIO_CRM_CLK               CRM_GPIOF_PERIPH_CLOCK
#endif

/**************** define print uart ******************/
#define PRINT_UART                       USART1
#define PRINT_UART_CRM_CLK               CRM_USART1_PERIPH_CLOCK
#define PRINT_UART_TX_PIN                GPIO_PINS_9
#define PRINT_UART_TX_GPIO               GPIOA
#define PRINT_UART_TX_GPIO_CRM_CLK       CRM_GPIOA_PERIPH_CLOCK
#define PRINT_UART_TX_PIN_SOURCE         GPIO_PINS_SOURCE9
#define PRINT_UART_TX_PIN_MUX_NUM        GPIO_MUX_1

/******************* define button *******************/
typedef enum
{
  USER_BUTTON                            = 0,
  NO_BUTTON                              = 1
} button_type;

#define USER_BUTTON_PIN                  GPIO_PINS_0
#define USER_BUTTON_PORT                 GPIOA
#define USER_BUTTON_CRM_CLK              CRM_GPIOA_PERIPH_CLOCK

/**
  * @}
  */

/** @defgroup BOARD_exported_functions
  * @{
  */

/******************** functions ********************/
void at32_board_init(void);

/* led operation function */
void at32_gpio_low(en_type led);
void at32_gpio_high(en_type led);
void at32_gpio_toggle(en_type led);

/* button operation function */
void at32_button_init(void);
button_type at32_button_press(void);
uint8_t at32_button_state(void);
uint8_t fldrv_read_slave_addr(void);		//读取从机地址
uint8_t fldrv_read_test_key(void);			//读测试按键键值
/* delay function */
void delay_init(void);
void delay_us(uint32_t nus);
void delay_ms(uint16_t nms);
void delay_sec(uint16_t sec);

/* printf uart init function */
void uart_print_init(uint32_t baudrate);

void fldrv_board_init(void);
/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif

